var swiper,setVue;
var stopRise = stopRise || {};
var tabGlobal = {};
tabGlobal.scrollHTie = 0;  // 用于记录tab切换前后页面位置变化
tabGlobal.scrollHJiYin = 0;
tabGlobal.scrollHJianKong = 0;
tabGlobal.ajaxFlag = 0;  // ajax请求锁
tabGlobal.limitJiYin = 0; //请求 或者 刷新接口
tabGlobal.limitJianKong = 0; //请求 或者 刷新接口
tabGlobal.coverErrorFlag = 1; //请求 或者 刷新接口
tabGlobal.switchTab = '.outline';  //页面当前展示tab
tabGlobal.pageId = 'pdt_pms_269';
tabGlobal.url_ver = {'url_ver':'SJCGBS-14521'};
tabGlobal.pageIdHasSend = false; // 页面埋点是否发过

			
stopRise = (function(){
	stopRise.initData = function(flag){
			$.ajax({
				type:'get',
				url:hxmConf.hxmAjaxUrl,
				dataType:'json',
				data:{
					'op':'getLimitUpSummary'
				},
				cache:false,
				timeout:10000,
			})
			.fail(function(){
				tabGlobal.ajaxFlag = 0;
				if(flag == 'start'){
					$('.load-box').addClass('hide');
					$('.load-error').removeClass('hide');
					tabGlobal.coverErrorFlag = 1;  

					if(!tabGlobal.pageIdHasSend){
						hxmPageStat({'id':tabGlobal.pageId,'url_ver':'SJCGBS-14521'});
						tabGlobal.pageIdHasSend = true;
					}
				}
			})
			.done(function(data){
				tabGlobal.ajaxFlag = 0;
				try {
					if(data.code == 0 && !$.isEmptyObject(data.data)){
						if(flag == 'start' && !tabGlobal.pageIdHasSend){
							hxmPageStat({'id':tabGlobal.pageId,'url_ver':'SJCGBS-14521'});
							tabGlobal.pageIdHasSend = true;
						}

						tabGlobal.urlData = data.data;
						$('.bottom_fixed_wrap').css('opacity',1);
						(flag == 'start') && (stopRise.setRenderVue());
						if(flag == 'refresh'){
							setVue.limitData = tabGlobal.urlData;
							setVue.isUpdate = tabGlobal.urlData.isUpdating;
						}
					} else if(data.code==-3 || data.code==-1){
						var url = '//ozone.10jqka.com.cn/tg_templates/vaserviece/limitUp/index.html';
						window.location.replace(url);

					}

				} catch(e) {
					console.log(e);
				}
			})
	},
	stopRise.setRenderVue = function(){
		setVue = new Vue({
			el:'.vueBox',
			data:{
				limitData : tabGlobal.urlData,
				isUpdate : tabGlobal.urlData.isUpdating
			},
			computed:{
				nextdayGetMoney:function(){  //赚钱效应强弱计算
					if(typeof this.limitData.yesterdayLimit.endGrade == 'number'){
						var gradeTxt;
						var grade = parseInt(this.limitData.yesterdayLimit.endGrade);
						if(grade >= 80){
							gradeTxt = '极强';
						}else if(grade >= 70 && grade < 80){
							gradeTxt = '强';
						}else if(grade >= 50 && grade < 70){
							gradeTxt = '偏强';
						}else if(grade >= 45 && grade < 50){
							gradeTxt = '偏弱';
						}else if(grade >= 35 && grade < 45){
							gradeTxt = '弱';
						}else if(grade < 35){
							gradeTxt = '极弱';
						}
						return gradeTxt;
					}else{
						return '--';
					}
				},
				limitNewNum:function(){
					if(typeof this.limitData.outLine.todayPlate.slowLimit == 'number' && typeof this.limitData.outLine.todayPlate.wordBoard == 'number'){
						var tt = parseInt(this.limitData.outLine.todayPlate.slowLimit) + parseInt(this.limitData.outLine.todayPlate.wordBoard);
						return tt;
					}else{
						return '--';
					}  
				},
				limitOldNum:function(){
					if(typeof this.limitData.outLine.yesterdayPlate.slowLimit == 'number' && typeof this.limitData.outLine.yesterdayPlate.wordBoard == 'number'){
						var tt = parseInt(this.limitData.outLine.yesterdayPlate.slowLimit) + parseInt(this.limitData.outLine.yesterdayPlate.wordBoard);
						return tt;
					}else{
						return '--';
					} 
				},
				averageRiseOne:function(){
					if(typeof this.limitData.yesterdayLimit.averageLimit == 'string'){
						return this.limitData.yesterdayLimit.averageLimit;
					}else{
						return '--';
					}
				}
			},
			methods:{
				transNumberData:function(str,type){
					if(typeof str == type){
						return str;
					}else{
						return '--';
					}
				},
				JumpToLimitStock:function(type){ //今日涨停股列表页面
					localStorage.setItem('stockPosition',$(window).scrollTop());
					hxmJumpPageStat(tabGlobal.pageId+tabGlobal.switchTab+'.stock.'+type,'pdt_pms_269_rise',{'url_ver':'SJCGBS-14521','to_frameid':'2804'});
					window.location.href = "oldStopStock.html?type="+type;
				},
				JumpToztDetail:function(code,key,market){  //涨停基因分数功能页面
					localStorage.setItem('ztPosition',$(window).scrollTop());
					hxmJumpPageStat(tabGlobal.pageId+tabGlobal.switchTab+'.my.'+key,'pdt_pms_269_gene',{'url_ver':'SJCGBS-14521','targid':'stock_'+code,'to_frameid':'2804'});
					window.location.href = 'oldztDetail.html?code='+code+'&marketId='+market;
				},
				JumpToFenShi:function(stockcode,key,market){//涨停股板块跳转
					if(!stockcode){
						return false;
					}
					hxmJumpNativeStat(tabGlobal.pageId+tabGlobal.switchTab+'.plate.'+key,'2205',{'url_ver':'SJCGBS-14521','targid':'stock_'+stockcode});
					window.location.href='client.html?action=ymtz^stockcode='+stockcode+'^marketid='+market+'^webid=2205';
				},
				swiperLeftClick:function(flag){
					flag == 1 ? (hxmClickStat(tabGlobal.pageId+tabGlobal.switchTab+'.today',tabGlobal.url_ver)) : (hxmClickStat(tabGlobal.pageId+tabGlobal.switchTab+'.yesterday',tabGlobal.url_ver));
				},
				JumpToLimitJiYin:function(){  //自选股跳转，查看更多
					hxmClickStat(tabGlobal.pageId+tabGlobal.switchTab+'.my.more',tabGlobal.url_ver);
					tabGlobal.switchTab = '.gene';
					stockGlobal.timenum = 0;
					$('.scroll_box').hide();
					$('.stockSearch').show();
					$('.limitEndControl').hide();
					$('body').addClass('vueBoxBack');
					$('.limitJiYin').addClass('growtwoRed');
					$('.limitTie').removeClass('growoneRed');
					$('.limitJianKong').removeClass('growthreeRed');
					tabGlobal.limitJiYin == 0 ? (AC()) : (stopStock.initAjax('refresh'));
					function AC(){
						tabGlobal.limitJiYin = 1;
						stopStock.initAjax('start');
						$('.load-box').removeClass('hide');
					}
				}
			}
		});
        
        //vue数据dom更新
		Vue.nextTick(function(){
			// 涨停股赚钱效应
			if(typeof tabGlobal.urlData.yesterdayLimit.endGrade == 'number'){
				var zero = parseInt(tabGlobal.urlData.yesterdayLimit.endGrade);
				(zero <= 0) && (zero = 0);
				(zero >=100) && (zero = 100);
				var rotateDeg = -17 + zero*2.14;
				$('.circle_trd').css({
					'transform':'rotate('+rotateDeg+'deg)',
					'-webkit-transform':'rotate('+rotateDeg+'deg)'
				});
			}else{
				$('.circle_trd').css({
					'transform':'rotate(-17deg)',
					'-webkit-transform':'rotate(-17deg)'
				});
			}


			if(getPlatform() == 'gphone'){
				$('.swiper-limitup-one div div i:nth-child(2)').css('bottom','0.16rem');
				$('.swiper-limitup-two div div i:nth-child(2)').css('bottom','0.16rem');
			}

			setTimeout(function(){
				if(localStorage.getItem('stockPosition')){
					$(window).scrollTop(localStorage.getItem('stockPosition'));
					localStorage.removeItem('stockPosition');
				}

				if(localStorage.getItem('ztPosition')){
					$(window).scrollTop(localStorage.getItem('ztPosition'));
					localStorage.removeItem('ztPosition');
				}
			},300);
			// 下拉刷新	
			setTimeout(function(){
				if(!localStorage.getItem('saveObj')){
					$('.load-box').addClass('hide');
				}
				var dpr = $('html').data('dpr');
			    var scrollObject = $('.scroll_box').pullScroll({
			        el:".vueBox",
			        downPullEnable:true,
			        upPullEnable:false,
			        scrollJudgeSize:150*dpr,
			        downPullEvent:function(){
			      		if(tabGlobal.ajaxFlag == 0){
			      			tabGlobal.ajaxFlag = 1;
			      			stopRise.initData("refresh");
			      			hxmClickStat(tabGlobal.pageId+tabGlobal.switchTab+'.refresh',tabGlobal.url_ver);
			      		}
			        }
			    });
			},500);

            //  滑动对象
			setTimeout(function(){
				swiper = new Swiper('.swiper-container',{
					slidesPerView:'auto',
			    	paginationClickable: true,
			    	loop:false,
			    	observer:true,
			    	observeParents:true,
					pagination:'.swiper-pagination',
				});
				if($('.swiper-pagination').find('span').length == 3){
					$('.swiper-pagination').find('span:last-child').remove();
				}
			},500);

			if(localStorage.getItem('saveObj')){ //本地对象存在，进入涨停基因页面
				setTimeout(function(){
					hxmClickStat(tabGlobal.pageId+tabGlobal.switchTab+'.gene',tabGlobal.url_ver);
					tabGlobal.switchTab = '.gene';
					stockGlobal.timenum = 0;
					$('.scroll_box').hide();
					$('.stockSearch').show();
					$('.limitEndControl').hide();
					$('body').addClass('vueBoxBack');
					$('.limitJiYin').addClass('growtwoRed');
					$('.limitTie').removeClass('growoneRed');
					$('.limitJianKong').removeClass('growthreeRed');
					tabGlobal.limitJiYin == 0 ? (AC()) : (stopStock.initAjax('refresh'));
					function AC(){
						tabGlobal.limitJiYin = 1;
						stopStock.initAjax('start');
						$('.load-box').removeClass('hide');
					}
				},1000);
			}

		});
	}

	return {
		initData:stopRise.initData,
		setRenderVue:stopRise.setRenderVue
	}
})();


;(function(){
	
	stopRise.initData("start");

	$('.load-box').removeClass('hide');
	$('.limitTie').addClass('growoneRed');

	//滚动到底部埋点
	bottomStat(tabGlobal.pageId+tabGlobal.switchTab+'.bottom',tabGlobal.url_ver);

	//接口异常，点击再次请求
	$('.cover').on('click',function(){
		$('.load-error').addClass('hide');
		$('.load-box').removeClass('hide');
		switch (tabGlobal.coverErrorFlag){
			case 1:
				stopRise.initData("start");
				break;
			case 2:
				stopStock.initAjax('start');
				break;
			case 3:
				limitControl.initAjax('start');
				break;		
		}
	})
	 //涨停概要
	$('.limitTie').on('click',function(){
		hxmClickStat(tabGlobal.pageId+tabGlobal.switchTab+'.outline',tabGlobal.url_ver);
		if(tabGlobal.switchTab == '.monitor'){
			tabGlobal.scrollHJianKong = $(window).scrollTop();
		}
		tabGlobal.switchTab = '.outline';
		stockGlobal.timenum = 1;
		$('.scroll_box').show();
		$('.stockSearch').hide();
		$('.limitEndControl').hide();
		$('body').removeClass('vueBoxBack');
		$('.limitTie').addClass('growoneRed');
		$('.limitJiYin').removeClass('growtwoRed');
		$('.limitJianKong').removeClass('growthreeRed');
		setTimeout(function(){
			stopRise.initData("refresh");
		},300);

		var td = setInterval(function(){
			if($('.swiper-container').height() > 1){
				swiper.slideTo(0);
				clearInterval(td);
			}
		},10);
		Vue.nextTick().then(function(){
			$(window).scrollTop(tabGlobal.scrollHTie);
		})
	});
	//涨停基因
	$('.limitJiYin').on('click',function(){
		hxmClickStat(tabGlobal.pageId+tabGlobal.switchTab+'.gene',tabGlobal.url_ver);
		if(tabGlobal.switchTab == '.monitor' && tabGlobal.limitJiYin == 1){
			$('#dd_limitCon li span ins').removeClass('topup');
			$('#dd_limitCon li span ins').removeClass('topdown');
			$('#dd_limitCon li span ins').removeClass('bottomup');
			$('#dd_limitCon li span ins').removeClass('bottomdown');
			tabGlobal.scrollHJianKong = $(window).scrollTop();
		}
		if(tabGlobal.switchTab == '.outline' && tabGlobal.limitJiYin == 1){
			tabGlobal.scrollHTie = $(window).scrollTop();
		}
		tabGlobal.switchTab = '.gene';
		stockGlobal.timenum = 0;
		$('.scroll_box').hide();
		$('.stockSearch').show();
		$('.limitEndControl').hide();
		$('body').addClass('vueBoxBack');
		$('.limitJiYin').addClass('growtwoRed');
		$('.limitTie').removeClass('growoneRed');
		$('.limitJianKong').removeClass('growthreeRed');
		tabGlobal.limitJiYin == 0 ? (AC()) : (stopStock.initAjax('refresh'));
		function AC(){
			tabGlobal.limitJiYin = 1;
			stopStock.initAjax('start');
			$('.load-box').removeClass('hide');
		}
		if(tabGlobal.limitJiYin == 1){
			var ts = setInterval(function(){
				if($('#cc_title li span').find('ins').length == 6){
					//设置表头排序图标 
					$('#cc_title li span ins').removeClass('topup');
					$('#cc_title li span ins').removeClass('topdown');
					$('#cc_title li span ins').removeClass('bottomup');
					$('#cc_title li span ins').removeClass('bottomdown');
					switch(stockGlobal.orderBy){
						case 'price':
							stockGlobal.sortType == 'desc' ? ($('#cc_title .high>span>ins:last-child').addClass('bottomup')) : ($('#cc_title .high>span>ins:first-child').addClass('topup'));
							break;
						case 'change':
							stockGlobal.sortType == 'desc' ? ($('#cc_title .code>span>ins:last-child').addClass('bottomup')) : ($('#cc_title .code>span>ins:first-child').addClass('topup'));
							break;
						case 'score':
							stockGlobal.sortType == 'desc' ? ($('#cc_title .rose>span>ins:last-child').addClass('bottomup')) : ($('#cc_title .rose>span>ins:first-child').addClass('topup'));
							break;
					}

					clearInterval(ts);
				}
			
			},10);
		}


		Vue.nextTick().then(function(){
			$(window).scrollTop(0);
		});
	});

	//涨停监控
	$('.limitJianKong').on('click',function(){
		hxmClickStat(tabGlobal.pageId+tabGlobal.switchTab+'.monitor',tabGlobal.url_ver);
		if(tabGlobal.switchTab == '.gene' && tabGlobal.limitJianKong == 1){
			$('#cc_title li span ins').removeClass('topup');
			$('#cc_title li span ins').removeClass('topdown');
			$('#cc_title li span ins').removeClass('bottomup');
			$('#cc_title li span ins').removeClass('bottomdown');
		}
		if(tabGlobal.switchTab == '.outline' && tabGlobal.limitJianKong == 1){
			tabGlobal.scrollHTie = $(window).scrollTop();
		}
		tabGlobal.switchTab = '.monitor';
		stockGlobal.timenum = 1;
		$('.scroll_box').hide();
		$('.stockSearch').hide();
		$('.limitEndControl').show();
		$('body').addClass('vueBoxBack');
		$('.limitTie').removeClass('growoneRed');
		$('.limitJiYin').removeClass('growtwoRed');
		$('.limitJianKong').addClass('growthreeRed');
		$('.rose>span>ins:last-child').addClass('bottomup'); //默认设置涨幅开关
		tabGlobal.limitJianKong == 0 ? (BC()) : (limitControl.initAjax('refresh'));
		function BC(){
			tabGlobal.limitJianKong = 1;
			limitControl.initAjax('start');
			$('.load-box').removeClass('hide');
		}

		if(tabGlobal.limitJianKong == 1){
			var td = setInterval(function(){

				if($('#dd_limitCon li span').find('ins').length == 10){
					$('#dd_limitCon li span ins').removeClass('topup');
					$('#dd_limitCon li span ins').removeClass('topdown');
					$('#dd_limitCon li span ins').removeClass('bottomup');
					$('#dd_limitCon li span ins').removeClass('bottomdown');
					switch (controlGlobal.orderType){
						case 'rise':
							controlGlobal.sortType == 'desc' ? ($('#dd_limitCon .rose>span>ins:last-child').addClass('bottomup')) : ($('#dd_limitCon .rose>span>ins:first-child').addClass('topup'));
							break;
						case 'fiveRise':
							controlGlobal.sortType == 'desc' ? ($('#dd_limitCon .high>span>ins:last-child').addClass('bottomup')) : ($('#dd_limitCon .high>span>ins:first-child').addClass('topup'));
							break;
						case 'sell':
							controlGlobal.sortType == 'desc' ? ($('#dd_limitCon .push>span>ins:last-child').addClass('bottomup')) : ($('#dd_limitCon .push>span>ins:first-child').addClass('topup'));
							break;
						case 'buy':
							controlGlobal.sortType == 'desc' ? ($('#dd_limitCon .pull>span>ins:last-child').addClass('bottomup')) : ($('#dd_limitCon .pull>span>ins:first-child').addClass('topup'));
							break;
						case 'maxRise':
							controlGlobal.sortType == 'desc' ? ($('#dd_limitCon .rise>span>ins:last-child').addClass('bottomup')) : ($('#dd_limitCon .rise>span>ins:first-child').addClass('topup'));
							break;				
					}

					clearInterval(td);
				}
			},10);
		}

		Vue.nextTick().then(function(){
			$(window).scrollTop(tabGlobal.scrollHJianKong);
		});

	});

	// 滑动到底部埋点
	function bottomStat(stat, extobj){
	    $(window).on('scroll', function(){
	        var dpr = $('html').data('dpr') ? $('html').data('dpr') : 1; // 页面dpr
	        var windowHeight = getPlatform() == 'iphone' ? window.screen.height : $(window).height();//分辨率的高度
	        var scrollHeight = $(window).scrollTop() / dpr;//document.documentElement.scrollTop;//滚动的高度
	        var totalHeight = $(document).height() / dpr;//文档的总高度
	        if((scrollHeight) >= (totalHeight - windowHeight)){
	            hxmOnceStat(stat,extobj);
	        }
	    });
	}


})();